stage.set_background("space")
stage.disable_all_walls()
instructions = codesters.Text("Use <- and -> to avoid the spikes!", 0, 200, "orange")
ship = codesters.Sprite("ufo", 0, -225)
ship.set_size(.5)
stage.wait(2)
def left_key():
ship.move_left(20)
stage.event_key("left", left_key)
def right_key():
ship.move_right(20)
stage.event_key("right", right_key)
score = 0
spike_interval = 1.5
spike_speed = -4
spike_gap = 200
def make_spikes():
random_left_length = random.randint(50, 350)
left_spike = codesters.TriangleIso(0, 300, 50, random_left_length, "red")
left_spike.set_rotation(-90)
left_spike.set_left(-250 + .5*random_left_length-25)
left_spike.set_y_speed(spike_speed)
right_length = 500 - (random_left_length + spike_gap)
right_spike = codesters.TriangleIso(0, 300, 50, right_length, "red")
right_spike.set_rotation(90)
right_spike.set_right(250 - .5*right_length+25)
right_spike.set_y_speed(spike_speed)
def interval():
global score
make_spikes()
score += 1
stage.event_interval(interval, spike_interval)
def collision(sprite, hit_sprite):
ship.set_physics_off()
stage.event_interval(None)
ship.set_say_color("orange")
ship.say("You scored " + str(score) + " points!")
ship.event_collision(collision)
while(ship.get_say_text() == None):
stage.wait()
else:
ship.event_collision(None)
stage.wait(3)
question1 = MCQ(1,"","","","","","", "row")
question1.set_prompt(" 1) In which event do we call make_spikes()?")
question1.set_choice_A('left_key')
question1.set_choice_B('right_key')
question1.set_choice_C('interval')
question1.set_choice_D('collision')
question1.set_correct("C")
question2 = MCQ(2,"","","","","","", "row")
question2.set_prompt("2) How often do we make a pair of spikes with make_spikes()?")
question2.set_choice_A('1 time inside the interval event')
question2.set_choice_B('2 times for the left and right spikes')
question2.set_choice_C('Once every 1.5 seconds as stored in spike_interval')
question2.set_choice_D('Unknown frequency')
question2.set_correct("C")
question3 = MCQ(3,"","","","","","", "row")
question3.set_prompt("3) What do we call the use of + to combine strings?\nLook at the second to last line!")
question3.set_choice_A('String concatenation')
question3.set_choice_B("String addition")
question3.set_choice_C('String fusion')
question3.set_choice_D('String math')
question3.set_correct("A")
repeat_test = True
stop_test = False
def test_script():
global repeat_test
global stop_test
try:
tval1 = question1.correct
except:
tval1 = "DNE"
try:
tval2 = question2.correct
except:
tval2 = "DNE"
try:
tval3 = question3.correct
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == True, " ")
t1.add_failure(tval1 == False, "Q1 wrong")
t1.add_failure(tval1 == "DNE", " ")
t2 = TestObjective()
t2.add_success(tval2 == True, " ")
t2.add_failure(tval2 == False, "Q2 wrong")
t2.add_failure(tval2 == "DNE", " ")
t3 = TestObjective()
t3.add_success(tval3 == True, " ")
t3.add_failure(tval3 == False, "Q3 wrong")
t3.add_failure(tval3 == "DNE", " ")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
#tester.display_first_feedback()
if repeat_test == False:
stop_test = True
test_counter = 0
def repeat_tests():
global stop_test
global test_counter
if stop_test == False:
test_script()
if test_counter >= 100:
stop_test = True
stage.event_interval(repeat_tests, .2)